<?php
	session_start();
	require_once("../db_connect.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../../css/css.css" type="text/css" />
<link rel="stylesheet" href="../../css/table_css.css" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.corner.js"></script>
<script type="text/javascript">

	//未入力項目をチェックする
	function chValie() {
	// 入力必須項目（「,」で区切って追加可能）
	ess = new Array("Family_Name","Given_Name","Family_Kana","Given_Kana","Nick_Name","Login_ID","Password","K_Password","Phone_Number","eMail","K_eMail");
	for(i=0; i<ess.length; i++) {
	 txt = document.userForm.elements[ess[i]].value;
	 if(txt == "") {
	   alert("未入力の項目があります");
	   return false;
	 }
	}
	return true;
	}

	var pass_flg=0;
	var mail_flg=0;
	 $(document).ready(function(){
		 $('#pass').focusout(function(){
			 	if(pass_flg!=0){
					error_check("pass","re_pass","pass_error_check","パスワード");
			 	}
			 	pass_flg=1;
		 });
		 $('#re_pass').focusout(function(){
				error_check("pass","re_pass","pass_error_check","パスワード");
		 });
		 $('#mail').focusout(function(){
			 if(mail_flg!=0){
				error_check("mail","re_mail","mail_error_check","メールアドレス");
			 }
			 mail_flg=1;
		 });
		 $('#re_mail').focusout(function(){
				error_check("mail","re_mail","mail_error_check","メールアドレス");
		 });
	});

	function error_check(a,b,c,d){
		if($("#"+a).val()!=$("#"+b).val()){
			$('#'+c).html(d+"が一致しません");
		}else{
			$('#'+c).html("");
		}
	}


	$(document).ready(
			function() {
				$("#volunteer").click(function () {
					$("#target").attr({
						action: "./PHP/serch_function/index_search.php?target=volunteer"
					});
				});

				$("#thread").click(function () {
					$("#target").attr({
						action: "./PHP/serch_function/index_search.php?target=threads"
					});
				});

				$('.box').corner();
				$('.box2').corner();
				$('.box3').corner();
				$('.box4').corner();
				<?php
					echo array_key_exists("error",$_SESSION)?"login_error('".htmlspecialchars($_SESSION['error'],ENT_QUOTES,"UTF-8")."');":"";
					unset($_SESSION["error"]);
				?>
		});
		function login_error(error){
			alert(error);
		}
 </script>
<title>ボランティア詳細情報</title>
</head>
<body>
	<div id="container">
		<div id="header" class="box4">
			<div id="header_box" >
				<div id="title">
				</div>
				<div id="search_box">
					<a href="#" id="volunteer">ボランティア</a>｜<a href="#" id="thread">掲示板</a>
					<form method="post" action="../search_function/search_display_free.php?target=volunteer" id="target">
						<input type="text"  name="search_word"><br />
						<input type="submit" value="検索する" id="search_button">
					</form>
				</div>
			</div>
		</div>
		<div id="rightnavi" class="box">
		<?php if(empty($_SESSION["user_name"])&&empty($_SESSION["user_id"])){?>
			<h3>ログインフォーム</h3>
			<form method="post" action="./user_function/UserLogin.php">
				ID：　　<input type="text" name="id" size="10"><br />
				PASS：<input type="text" name="pass" size="10"><br />
				<input style="margin:10px 0 0 39px;" type="image" src="../img/login.png" alt="送信ボタン" name="submit" align="middle">
			</form>
			<a  href="./PHP/User_create.php"><img style="margin:-20px 0 0 39px;" src="../img/newuser.png" border="0"></a>
		<?php }else{?>
				<img src="../../img/kaiinlogo.png" id="kaiinlogo" />
				<p>ようこそ<?php echo $_SESSION['nick_name']?>さん！</p>
				<p><a href="../user_function/user_infomation.php">会員情報表示</a></p>
				<p><a href="../user_function/user_update.php">会員情報変更</a></p>
				<p><a href="../user_function/user_display_application.php">申請中ボランティア</a></p>
				<p><a href="../user_function/user_display_volunteer.php">提供中ボランティア</a></p>
				<p><a href="../volunteer_function/volunteer_information_insert.php">ボランティア作成</a></p>
				<p><a href="../user_function/logout.php">ログアウト</a></p>
				<br />
		<?php }?>
		<img src="../../img/keizilogo.png" id="keizilogo" />
<ul class="menu_margin">
<div id="thread_title_look">
<?php

	//スレッド項目取得
	$sql = "SELECT t.thread_id,count(thread_name) as thread_count,t.thread_name,max(r.response_date) as response_date,t.thread_id FROM thread AS t LEFT OUTER JOIN response AS r ON t.thread_id = r.thread_id group by t.thread_name order by response_date desc limit 0,5";
	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//スレッド表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
	  echo "<li><a href='../response.php?thread_id=".$data['thread_id']."'>";
	  echo mb_strlen($data['thread_name'])>=9?mb_substr($data['thread_name'],0,9)."...":$data['thread_name'];
	  echo "</a></li>";
	}
?>
				</ul>
		<div id="more"><a href="../PHP/thread.php" >もっと見る...</a></div>
	</div>
<div id="main"  class="box3">
<br />
<h1 align="center">ボランティア詳細情報</h1>
<?php
	$volunteer_information_id  = htmlspecialchars($_GET['volunteer_information_id'],ENT_QUOTES,"UTF-8").",";

		$sth = "SELECT count(v.treatment_id) count
							FROM volunteer_information v,
							(SELECT *
							FROM user
							WHERE user_id = (
							SELECT DISTINCT user_id
							FROM volunteer_information
							WHERE volunteer_information_id =? )
							)u, sub_category c,treatment t
							WHERE v.user_id = u.user_id
							AND c.sub_category_id = v.sub_category_id
							AND v.volunteer_information_id =?
							AND v.treatment_id = t.treatment_id";

			$data = array($volunteer_information_id,$volunteer_information_id);

			$res =& $db->query($sth, $data);	//SQLを実行して、結果を $res に代入
			if (PEAR::isError($res)) {			//SQLの実行に失敗すればここでエラー文を出力
				die($res->getMessage());
			}
		$row_count = 0;
		while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {	//SQLの実行結果を表示
			$row_count = $row['count'];
		}

		$sth = "SELECT v.volunteer_information_id, v.volunteer_name, v.sub_category_id, v.content, v.age, v.target_gender, v.work_time, v.updata_date, v.posted_date, v.activity_date, v.end_time, v.location, v.access, v.conditions, u.family_name, v.application_number, v.treatment_id, u.group_name, u.information, u.url, u.group_id, v.pref, sub_category_name, t.treatment_name, u.group_name as user_group_name,g.group_name as group_group_name
FROM volunteer_information v, (
SELECT *
FROM user
WHERE user_id = (
SELECT DISTINCT user_id
FROM volunteer_information
WHERE volunteer_information_id =? )
)u, sub_category c, treatment t, `group` g
WHERE v.user_id = u.user_id
AND c.sub_category_id = v.sub_category_id
AND v.volunteer_information_id =?
AND v.treatment_id = t.treatment_id
AND u.group_id = g.group_id";

	$data = array($volunteer_information_id,$volunteer_information_id);

	$res =& $db->query($sth, $data);	//SQLを実行して、結果を $res に代入
	if (PEAR::isError($res)) {			//SQLの実行に失敗すればここでエラー文を出力
		die($res->getMessage());
	}
	$i=1;
	while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {	//SQLの実行結果を表示
		if($i==1){
			echo "<table id='table-02'>";
			echo "<tr><th >ボランティア名</th><td>"	.$row['volunteer_name']		."</td></tr>";
		    echo "<tr><th>カテゴリ名</th><td>"	.$row['sub_category_name']	."</td></tr>";
		    echo "<tr><th>活動内容</th><td height='250px;'>"		.$row['content']			."</td></tr>";
			echo "<tr><th>対象年齢</th><td>"		.$row['age']				."</td></tr>";
			echo "<tr><th>対象性別</th><td>"		.$row['target_gender']		."</td></tr>";
		    echo "<tr><th>勤務時間</th><td>"		.$row['work_time']			."</td></tr>";
			echo "<tr><th>投稿更新日時</th><td>"	.$row['updata_date']		."</td></tr>";
		    echo "<tr><th>掲載終了日時</th><td>"	.$row['posted_date']		."</td></tr>";
		    echo "<tr><th>活動時間</th><td>"		.$row['activity_date']		."</td></tr>";
			echo "<tr><th>終了時間</th><td>"		.$row['end_time']			."</td></tr>";
			echo "<tr><th>活動場所</th><td>"		.$row['pref']			."</td></tr>";
		    echo "<tr><th>移動手段</th><td>"		.$row['access']				."</td></tr>";
			echo "<tr><th>条件</th><td>"			.$row['conditions']			."</td></tr>";
		    echo "<tr><th>情報提供者名</th><td>" .$row['family_name']. "</td></tr>";
		    echo "<tr><th>待遇</th><td>";
		}
			echo $row['treatment_name']."　";
		if($i==$row_count){
		    echo "</td></tr>";
			echo "<tr><th>グループ名</th><td>"		.$row['user_group_name']			."</td></tr>";
			echo "<tr><th>団体照会文</th><td>"		.$row['information']		."</td></tr>";
			echo "<tr><th>URL</th><td>"	.$row['url']		."</td></tr>";
			echo "<tr><th>団体分類</th><td>"		.$row['group_group_name']			."</td></tr>";
			echo "</table>";
		}
		$i++;
	}
?>
</div>
<div id="space"></div>
</div>
    </body>
</html>
